package com.gdit.zax.servletjsp;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gdit.zax.Constant;
import com.gdit.zax.dao.CourseDao;
import com.gdit.zax.dao.UserDao;
import com.gdit.zax.dao.VideoDao;
import com.gdit.zax.entitys.UserInfo;
import com.gdit.zax.factory.DAOFactory;
import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.Repost;
import com.gdit.zax.utils.webUtil;

/**
 * 上传视频界面前加载数据
 * @author lenovo
 *
 */
public class LoadPubVideo extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String token = webUtil.getCookie(request, "LoginCookie");
		Connection conn = DBUtil.getConnection();
		
		if (conn == null) {
			Repost.dberror(request, response);
		}
		
		DAOFactory dao = DAOFactory.init(conn, request, response);
		UserDao udao = dao.getUserDao();
		CourseDao cdao = dao.getCourseDao();
		VideoDao vdao = dao.getVideoDao();
		
		UserInfo info = udao.getInfo(Constant.LOGINTYPE_WEB, token);
		
		if (info==null) {
			Repost.nologin(response);
			return;
		}
		
		
		
		//上传标识
		request.setAttribute("flag", "t" + System.currentTimeMillis());
		//课程分类
		request.setAttribute("data_coursetype", cdao.getAllCoursetype());
		//用户拥有的课程
		request.setAttribute("data_course", cdao.getAllCourse(info.getId()));
		//课程的章节
		request.setAttribute("data_course", vdao.getAllSectionByUser(info.getId()));
		//视频分类
		request.setAttribute("data_videotype", vdao.getAllVideotype());
		Repost.success("publishvideo.jsp", request, response);
	}

}
